
var apps, views, merchant,
	first = 0, last = 10;
mui.plusReady(function () {
    views = bexta.getWebview();
    merchant = bexta.getStorage(MERCHANT);
    bexta.ajax(api.order_list, function(res){
    		initVue(res);
    }, {data:{uid:merchant.uid, type:views.type, firstrow:first, listrow:last}});
});
function initVue(res) {
	apps = new Vue({
		el:"#vueMain",
		data:{
			list:res,
			first:res.length,
			last:last
		},
		mounted:function(){
			var self = this;
			document.querySelector('.loading').classList.add('loadRun');
			mui.previewImage();
			mui.init({
			  	pullRefresh : {
			    		container:"#refreshContainer",
			    		down:{
			    			height:50,
			    			auto:false,
			    			callback:function(){
			    				 bexta.ajax(api.order_list, function(res){ 
			    				 	self.list = res;
			    				 	  mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
			    				 }, {data:{uid:merchant.uid, type:views.type, firstrow:0, listrow:self.last}});
			    			}
			    		},
				    up : {
				      	height:50,
				      	auto:false,
				      	contentrefresh : "正在加载...",
				      	contentnomore:'没有更多数据了',
				      	callback :function(){
				      		var that = this;
				      		bexta.ajax(api.order_list, function(res){
				      			var len = res.length;
				      			if( len == 0 || len < self.last ){
				      				that.endPullupToRefresh(true);
				      			}else{
				      				that.endPullupToRefresh(false);
				      			}
				      			if( len > 0 ){
				      				mui.each(res, function(){
				      					self.list.push(this);
				      				});
				      				self.first += len;
				      			}
				      		}, {data:{uid:merchant.uid, type:views.type, firstrow:self.first, listrow:self.last}})
				      	}
				    }
			  	}
			});
		},
		updated:function(){
			mui.previewImage();
		}
	});
}